package com.qiye.pointsserver.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qiye.pointsserver.model.entity.Userinfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qiye.pointsserver.model.vo.UserInfoVO;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

/**
* @author Lenovo
* @description 针对表【sys_userinfo(用户信息表)】的数据库操作Mapper
* @createDate 2025-07-07 16:40:40
* @Entity com.qiye.pointsserver.model.entity.Userinfo
*/
public interface UserinfoMapper extends BaseMapper<Userinfo> {

    @Select("""
    SELECT 
      u.email, 
      ui.id, ui.name, ui.phone, ui.gender, ui.company, 
      ui.birthdate, ui.create_time, ui.update_time
    FROM 
      sys_userinfo AS ui
    JOIN
      sys_user AS u ON ui.user_id = u.id
    WHERE
      ui.user_id = #{userId}
""")
    UserInfoVO getUserInfoByUserId(@Param("userId") Integer userId);


    @Select("""
    SELECT 
      u.email, u.role,
      ui.id, ui.name, ui.phone, ui.gender, ui.company, 
      ui.birthdate, ui.create_time, ui.update_time
    FROM 
      sys_userinfo AS ui
    JOIN 
      sys_user AS u ON ui.user_id = u.id
    WHERE
      (#{keyword} IS NULL OR #{keyword} = '' 
       OR ui.name LIKE CONCAT('%', #{keyword}, '%') 
       OR ui.phone LIKE CONCAT('%', #{keyword}, '%') 
       OR ui.company LIKE CONCAT('%', #{keyword}, '%'))
    ORDER BY ui.create_time DESC
""")
    IPage<UserInfoVO> searchPage(Page<?> page, @Param("keyword") String keyword);


}




